package com.springBoot.springBootSysCore.config.task;

import com.springBoot.springBootSysCore.modules.repository.system.SysUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Configurable
@EnableScheduling
public class ScheduledTasks {

    @Autowired
    private SysUserRepository sysUserRepository;

    //十分钟一次
    @Scheduled(fixedRate = 1000 * 60 * 10)
    @Transactional
    public void reportCurrentTime(){
        sysUserRepository.updateSysUserMember();
        System.out.println ("Scheduling Tasks Examples: The time is now " + dateFormat ().format (new Date()));
    }

    //每1分钟执行一次
//    @Scheduled(cron = "0 */1 *  * * * ")
//    public void reportCurrentByCron(){
//
//        System.out.println ("查询修改会员过期用户会员状态" + dateFormat ().format (new Date ()));
//    }

    private SimpleDateFormat dateFormat(){
        return new SimpleDateFormat ("HH:mm:ss");
    }

}
